package com.lgl.scsheader.system.controller;

import com.lgl.scsheader.base.controller.BaseController;
import com.lgl.scsheader.system.model.SysMenu;
import com.lgl.scsheader.system.service.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 菜单controller
 */
@RestController
@RequestMapping(value="/menu")
public class MenuController extends BaseController {
	private Logger logger = LoggerFactory.getLogger(MenuController.class);

	@Resource(name="menuService")
	private MenuService menuService;
	
	/**
	 * 显示菜单列表
	 * @return
	 */
	@RequestMapping(value = "listAllMenu")
	public Object listAllMenu(){
		return menuService.listAllMenu();
	}

	/**
	 * 保存菜单信息
	 * @param menu 菜单对象
	 * @return 更新的行数
	 */
	@RequestMapping(value="/add")
	public Object add(@RequestBody SysMenu menu){
		return menuService.saveMenu(menu);
	}

	/**
	 * 保存编辑
	 * @param 
	 * @return
	 */
	@RequestMapping(value="/edit")
	public Object edit(@RequestBody SysMenu menu){
		return menuService.editMenu(menu);
	}

	/**
	 * 通过ID删除菜单
	 */
	@RequestMapping(value="/deleteMenuById")
	public Object deleteMenuById(HttpServletRequest request) {
		String menuId = request.getParameter("menuId");
		try{
			menuService.deleteMenuById(menuId);
            return "0";
		} catch(Exception e){
			logger.error(e.getMessage(), e);
		}
		return "1";
	}
}
